<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <title>企微任务宝</title>
  <script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
  <script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>
  <!--    微信H5开发-->
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.2/vue.global.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.js"></script>
  <script src="js/request.js"></script>
  <script src="js/wx.js"></script>
  <!--  <script src="https://cdn.bootcdn.net/ajax/libs/es6-promise/4.2.8/es6-promise.js"></script>-->
  <style>
    [v-cloak] {display: none;}
  </style>
</head>
<body>
<noscript>
  <strong>We're sorry but qwrwb doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app" v-cloak>
  测试
  <div>
    {{result}}
  </div>
  <button @click="getCurrentUser">获取当前用户</button>
  <button @click="openUserProfile">打开个人信息页接口</button>
</div>
<script>
  new Vue({
    el: '#app',
    data: {
      result: '',
      userId: 'wmEAlECwAAHrbWYDetiu3Af13xlYDAAA'
    },
    mounted() {
      var self = this;

      window.wxUtils.init().then(function() {
        console.log('成功')
        self.result = '成功'

      }).catch(function (err) {
        self.result = '失败'+JSON.stringify(err)
      })
    },
    methods: {
      openUserProfile() {
        window.wx.invoke('openUserProfile', {
          "type": 1, //1表示该userid是企业成员，2表示该userid是外部联系人
          "userid": this.userId //可以是企业成员，也可以是外部联系人
        }, function(res){
          console.log(res)
          if(res.err_msg != "openUserProfile:ok"){
            //错误处理
          }
        });
      },
      getCurrentUser() {
        let self = this;
        wx.invoke('getCurExternalContact', {
        }, function(res){
          console.log(res)
          if(res.err_msg == "getCurExternalContact:ok"){
            self.userId  = res.userId ; //返回当前外部联系人userId
          }else {
            //错误处理
          }
        });
      }
    }
  })

</script>
</body>
</html>
